<template>
	<view class="page">
		<view class="header">
			<image src="../../static/icon/member-active.png" class="face"></image>
			
			<view class="info-wrapper" v-if="userIsLogin">
				
				<view class="nickname">
					<navigator url="meinfo">{{loginUser.userName}}</navigator>
				</view>
				<view class="tel">
					{{loginUser.tel}}
				</view>
				
			</view>
			
			<view class="info-wrapper" v-else>
				<navigator url="login">
					注册/登录
				</navigator>
			</view>
			
			
			<view class="set-wapper">
				
				<text class="iconfont icon-xian"></text>
				
			</view>
		</view>
		
		<view class="menus">
			<view class="menu-item" v-for="(item,index) in menuArr" :key="index" @click="itemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		
		<view class="heading">
			智慧门诊
		</view>
		
		<view class="content">
			<view class="content-item" v-for="(item,index) in menuArr" :key="index" @click="itemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		
		<view class="heading">
			新冠疫苗
		</view>
		
		<view class="content">
			<view class="content-item" v-for="(item,index) in menuArr" :key="index" @click="itemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		
		<view class="heading">
			其它
		</view>
		
		<view class="content">
			<view class="content-item" v-for="(item,index) in menuArr" :key="index" @click="itemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userIsLogin:false ,
				loginUser:{},
				menuArr:[
					{
						icon: 'iconfont icon-diqiu',
						title: '我的家人',
						path: '/pages/appointment/appointment'
					},
					{
						icon: 'iconfont icon-dazhen',
						title: '预约记录',
						path: '/pages/me/reservation_recored'
					},
					{
						icon: 'iconfont icon-feiji',
						title: '我的收藏',
						path: '/pages/appointment/appointment'
					}
				]
			}
		},
		async onShow() {
			const res = await this.$request({
				url:'/api/v1/user/personal',
				header:{
					'Authorization': 'Bearer ' + this.$getStorageSync("token") 
				},
				method:'GET'
			}) ;
			
			if(res.data.data!=null) {
				this.loginUser = res.data.data ;
				this.userIsLogin = true ;
				uni.setStorageSync("loginUser",res.data.data) ;
			} else {
				this.loginUser = {} ;
				this.userIsLogin = false ;
				uni.removeStorageSync("loginUser") ;
			}
		
		},
		methods: {
			itemClick(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
	@import url("me.css");
</style>
